VERSION 5.00
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form frmCommodities 
   BackColor       =   &H00FFFFFF&
   Caption         =   "Edit/Delete Commodity Information"
   ClientHeight    =   4050
   ClientLeft      =   165
   ClientTop       =   705
   ClientWidth     =   11880
   Icon            =   "frmCommodities.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   4710
   ScaleMode       =   0  'User
   ScaleWidth      =   11997.62
   StartUpPosition =   1  'CenterOwner
   Begin VB.Frame fraButton 
      BackColor       =   &H80000005&
      BorderStyle     =   0  'None
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H000080FF&
      Height          =   615
      Left            =   120
      TabIndex        =   2
      Top             =   3240
      Width           =   11055
      Begin VB.CommandButton cmdClose 
         Appearance      =   0  'Flat
         BackColor       =   &H00E0E0E0&
         Caption         =   "OK"
         Height          =   315
         Left            =   5880
         MaskColor       =   &H0080C0FF&
         Style           =   1  'Graphical
         TabIndex        =   5
         Top             =   120
         UseMaskColor    =   -1  'True
         Width           =   1215
      End
      Begin VB.CommandButton cmdDelete 
         Appearance      =   0  'Flat
         BackColor       =   &H00E0E0E0&
         Caption         =   "&Delete All"
         Height          =   315
         Left            =   4320
         MaskColor       =   &H0080C0FF&
         Style           =   1  'Graphical
         TabIndex        =   4
         Top             =   120
         UseMaskColor    =   -1  'True
         Width           =   1215
      End
      Begin VB.CommandButton cmdClean 
         Appearance      =   0  'Flat
         BackColor       =   &H00E0E0E0&
         Caption         =   "&Clean Up"
         Height          =   315
         Left            =   2760
         MaskColor       =   &H0080C0FF&
         Style           =   1  'Graphical
         TabIndex        =   3
         Top             =   120
         UseMaskColor    =   -1  'True
         Visible         =   0   'False
         Width           =   1215
      End
   End
   Begin VB.Frame fraCommodity 
      BackColor       =   &H00FFFFFF&
      Caption         =   "Commodity Information"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H000080FF&
      Height          =   3015
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   11055
      Begin MSDataGridLib.DataGrid grdCommodities 
         Height          =   2535
         Left            =   180
         TabIndex        =   1
         TabStop         =   0   'False
         ToolTipText     =   "To Delete a Commodity highlight the row and press the Delete key."
         Top             =   300
         Width           =   10680
         _ExtentX        =   18838
         _ExtentY        =   4471
         _Version        =   393216
         HeadLines       =   2
         RowHeight       =   15
         TabAction       =   2
         WrapCellPointer =   -1  'True
         AllowDelete     =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Caption         =   "Total Commodities"
         ColumnCount     =   2
         BeginProperty Column00 
            DataField       =   ""
            Caption         =   ""
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   ""
            Caption         =   ""
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            BeginProperty Column00 
            EndProperty
            BeginProperty Column01 
            EndProperty
         EndProperty
      End
   End
End
Attribute VB_Name = "frmCommodities"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

' 2008-07-01, JFW, Commodities tag 120.

Dim WithEvents rsCommod As ADODB.Recordset
Attribute rsCommod.VB_VarHelpID = -1
Dim mblnActivate As Boolean

Public Sub ApplyAppearance()

    Dim str1 As String
    Dim str2() As String
    Dim i As Long
    
    On Error GoTo ExitHere
    
    str1 = g_clsReg.GetRegistryValue("frmCommodities", "")
    
    Debug.Print Now, "Apply " & str1
    
    If str1 <> "" Then
        str2 = Split(str1, ",")
        Do
            If i >= UBound(str2) Then Exit Do
            Select Case str2(i)
            Case "Top"
                Me.Top = CLng(str2(i + 1))
            Case "Left"
                Me.Left = CLng(str2(i + 1))
            Case "Width"
                Me.Width = CLng(str2(i + 1))
            Case "Height"
                Me.Height = CLng(str2(i + 1))
            End Select
            i = i + 2
        Loop
    End If
    DoEvents
    Call Form_Resize
    
ExitHere:

    Debug.Print Now, "ApplyAppearance " & Me.Top
    
End Sub

Public Sub SaveAppearance()

    Dim str1 As String
    If mblnActivate Then
        str1 = "Top," & Me.Top
        str1 = str1 & "," & "Left," & Me.Left
        str1 = str1 & "," & "Width," & Me.Width
        str1 = str1 & "," & "Height," & Me.Height
        If grdCommodities.Columns.Count > 4 Then
            g_clsReg.SetRegistryValue "frmCommodities", str1, REG_SZ
        End If
    End If
    
    Debug.Print Now, "SaveAppearance " & Me.Top
    
End Sub

'---------------------------------------------------------------------------------------
' Module    : UpdateCommodityGrid
' DateTime  : 9/1/2005
' Author    : Chris Elwell
' Purpose   : Updates the Commodity datagrid for the OrderID passed
' Call from : cmdAddToShipment_Click(), f1_LostFocus, and ClearShipFields
'---------------------------------------------------------------------------------------
'
Public Sub UpdateCommodityGrid(ByVal str1 As String)

    Dim strQuery As String
    Dim i As Long
    
    On Error GoTo EH
    
'    DebugPrint "UpdateCommodityGrid"
    
    Set rsCommod = New ADODB.Recordset
    
    strQuery = "SELECT "
    If NASCAR_VERSION >= "FSMSClient v800.2.2" Then
        strQuery = strQuery & " CommodityID, "
    End If
    strQuery = strQuery & " g_str79, g_str1275, g_str120, g_str80, g_str81, g_str82, g_str83, g_str84,"
    strQuery = strQuery & " g_str414, g_str1030, g_str78, g_str77, "
    If NASCAR_VERSION >= "FSMSClient v800.2.1" Then
        strQuery = strQuery + " MID, Document1, Document2, Document3, "
    End If
    strQuery = strQuery + " f1, Workstation"
    strQuery = strQuery + " FROM IntlCommodities"
    strQuery = strQuery + " WHERE f1 = '" & str1 & "'"
    strQuery = strQuery & " AND Workstation = '" & g_strComputerName & "'"
    strQuery = strQuery & " AND (g_str29 IS NULL OR g_str29 = '')"
    
    rsCommod.Open strQuery, g_connFSMSClient, adOpenKeyset, adLockOptimistic

    With grdCommodities
        Set .DataSource = rsCommod
        .ClearFields
        .ReBind
        For i = 0 To .Columns.Count - 1
            Select Case .Columns(i).Caption
            Case "CommodityID"
                .Columns(i).Width = 1200
            Case "g_str77"
                .Columns(i).Caption = "Weight"
                .Columns(i).Width = 750
                .Columns(i).Alignment = dbgRight
            Case "g_str78"
                .Columns(i).Caption = "Customs Val"
                .Columns(i).Width = 1100
                .Columns(i).Alignment = dbgRight
            Case "g_str79"
                .Columns(i).Caption = "Description"
                .Columns(i).Width = 2400
            Case "g_str80"
                .Columns(i).Caption = "Cntry of Mfg"
            Case "g_str81"
                .Columns(i).Caption = "Harmonized Code"
                .Columns(i).Width = 1100
            Case "g_str82"
                .Columns(i).Caption = "Quantity"
                .Columns(i).Width = 750
                .Columns(i).Alignment = dbgRight
            Case "g_str83"
                .Columns(i).Caption = "Export Lic #"
            Case "g_str84"
                .Columns(i).Caption = "Lic Expire Date"
            Case "g_str414"
                .Columns(i).Caption = "Unit of Measure"
            Case "g_str1030"
                .Columns(i).Caption = "Unit Value"
                .Columns(i).Width = 1100
                .Columns(i).Alignment = dbgRight
            Case "g_str1275"
                .Columns(i).Caption = "Part Number"
                .Columns(i).Width = 1200
            Case "g_str120"
                .Columns(i).Caption = "Marks"
                .Columns(i).Width = 1200
            Case "MID"
                .Columns(i).Width = 1200
            Case "Document1"
                .Columns(i).Width = 750
            Case "Document2"
                .Columns(i).Width = 750
            Case "Document3"
                .Columns(i).Width = 750
            Case "f1"
                .Columns(i).Visible = False
            Case "Workstation"
                .Columns(i).Visible = False
            End Select
        Next i
        
        .Caption = "Total Commodities: " & Str(rsCommod.RecordCount)
        
    End With
    
    For i = 1 To 500
        DoEvents
    Next i
    
    Call Initialize(Me)
    
Release:
    Set rsCommod = Nothing
    Exit Sub
EH:
    MsgBox Err.Description, vbCritical, "frmCommodities:UpdateCommodityGrid"
    Resume Release
     
End Sub

Private Sub cmdClean_Click()
    
    Dim intRet As Integer

    On Error GoTo EH
    
    grdCommodities.col = grdCommodities.col + 1
    DoEvents
    grdCommodities.Row = 0
    DoEvents
    
    With frmShip
        If .f1.Visible Then
            Call CleanAllCommodities(.f1.Text)
            Call UpdateCommodityGrid(.f1.Text)
        Else
            Call CleanAllCommodities(.cboCustID.Text)
            Call UpdateCommodityGrid(.cboCustID.Text)
        End If
    End With

    Call frmShip.SetCommodSummary
    DoEvents

    Exit Sub
EH:
    MsgBox Err.Description, vbCritical, "frmCommodities:cmdDelete_Click"

End Sub

'---------------------------------------------------------------------------------------
' Procedure : cmdClose_Click()
' DateTime  : 9/1/2005
' Purpose   : Hides form
'---------------------------------------------------------------------------------------
'
Private Sub cmdClose_Click()
    
    On Error Resume Next
    
    grdCommodities.col = grdCommodities.col + 1
    DoEvents
    grdCommodities.Row = 0
    DoEvents
    
    Call frmShip.SetCommodSummary
    
    Unload Me
    
End Sub

'---------------------------------------------------------------------------------------
' Procedure : cmdDelete_Click()
' DateTime  : 9/1/2005
' Purpose   : Verifes user wished to delete all defined Addresses, if yes calls sub to
'             delete all records in Commodities table and updates the grdAddresses.
'---------------------------------------------------------------------------------------
'
Private Sub cmdDelete_Click()
    Dim intRet As Integer

    On Error GoTo EH
    
    intRet = MsgBox("Are you sure you wish to delete all defined Commodities?", vbYesNo, "Confirm Delete All")
    If intRet = vbYes Then
        With frmShip
            If .f1.Visible Then
                Call DeleteIntlCommodities(.f1.Text)
                Call UpdateCommodityGrid(.f1.Text)
            Else
                Call DeleteIntlCommodities(.cboCustID.Text)
                Call UpdateCommodityGrid(.cboCustID.Text)
            End If
        End With
    End If

    Exit Sub
EH:
    MsgBox Err.Description, vbCritical, "frmCommodities:cmdDelete_Click"

End Sub

Private Sub Form_Activate()
    Dim i As Long
'    If Not mblnActivate Then
'        Me.Top = frmShip.Top + 1530
'    End If
    With frmShip
        If .f1.Visible Then
            Call UpdateCommodityGrid(.f1)
            fraCommodity.Caption = "Order ID " & .f1 & " Commodity Information"
        Else
            Call UpdateCommodityGrid(.cboCustID)
            fraCommodity.Caption = "Customer ID " & .cboCustID & " Commodity Information"
        End If
    End With
    For i = 1 To 5
        DoEvents
    Next i
    mblnActivate = True
    Call ApplyAppearance
End Sub

Private Sub Form_Initialize()
    mblnActivate = False
End Sub

Private Sub Form_Load()
    ' Don't save Form settings until fully Activate
    mblnActivate = False
End Sub

Private Sub Form_Resize()
    On Error GoTo EH
    If mblnActivate Then
        fraButton.Top = (Me.Height - fraButton.Height - 100) * Me.ScaleHeight / Me.Height
        fraCommodity.Height = (Me.Height - fraCommodity.Top - fraButton.Height - 300) * Me.ScaleHeight / Me.Height
        grdCommodities.Height = (fraCommodity.Height - 2 * grdCommodities.Top - 400) * Me.Height / Me.ScaleHeight
        
        Debug.Print grdCommodities.Height & " = (" & fraCommodity.Height & " - 2 * " & grdCommodities.Top & " - 400)"
        
        fraButton.Width = Me.Width - 2 * fraButton.Left - 100
        fraCommodity.Width = (Me.Width - 2 * fraCommodity.Left - 100) * Me.ScaleWidth / Me.Width
        grdCommodities.Width = (fraCommodity.Width - 2 * grdCommodities.Left - 100) * Me.Width / Me.ScaleWidth
        Call SaveAppearance
    End If
ErrorExit:
    Exit Sub
EH:
    DebugPrint "Error, frmCommodities:Form_Resize, " & Err.Description
End Sub

Private Sub Form_Unload(Cancel As Integer)
    On Error Resume Next
    Call SaveAppearance
    grdCommoditie.col = grdCommodities.col + 1
    DoEvents
    grdCommodities.Row = 0
    DoEvents
    Call frmShip.SetCommodSummary
End Sub

Private Sub grdCommodities_AfterColEdit(ByVal ColIndex As Integer)
    On Error Resume Next
'    DebugPrint "grdCommodities_AfterColEdit, " & "Value " & grdCommodities.Columns(ColIndex).Text & ", index " & ColIndex
End Sub

'---------------------------------------------------------------------------------------
' Procedure : grdCommodities_AfterColUpdate()
' DateTime  : 7/15/2004
' Modified  : 8/11/2004
' Change    : Added a check for Null before setting the bookmark. This allows records
'             to be added. Also added error handling.
' Purpose   : This commits the changes immediately after a column has been updated.
'             This keeps users from getting "Operation not allowed in this context" error.
'---------------------------------------------------------------------------------------
'
Private Sub grdCommodities_AfterColUpdate(ByVal ColIndex As Integer)
    On Error GoTo EH
    
'    DebugPrint "grdCommodities_AfterColUpdate, ColIndex " & ColIndex
    
    If grdCommodities.Bookmark >= 0 Then
        grdCommodities.Bookmark = grdCommodities.Bookmark
    End If
    
    If grdCommodities.AddNewMode = dbgAddNewPending Then
        grdCommodities.Row = 0
        grdCommodities.Row = grdCommodities.VisibleRows - 2
    End If
    
    ' 2011-04-25, JFW, If we're adding a new row then we don't have access to column data.
    On Error GoTo ErrorExit
    
    If grdCommodities.Columns(ColIndex).Caption = "Customs Val" Then
        If IsNumeric(grdCommodities.Columns("Customs Val").Text) Then
            If IsNumeric(grdCommodities.Columns("Quantity").Text) Then
                grdCommodities.Columns("Unit Value").Text = CDbl(grdCommodities.Columns("Customs Val").Text) / CDbl(grdCommodities.Columns("Quantity").Text)
            End If
        End If
    End If
    If grdCommodities.Columns(ColIndex).Caption = "Quantity" Then
        If IsNumeric(grdCommodities.Columns("Quantity").Text) Then
            If IsNumeric(grdCommodities.Columns("Unit Value").Text) Then
                grdCommodities.Columns("Customs Val").Text = Format(Round(CDbl(grdCommodities.Columns("Unit Value").Text) * CDbl(grdCommodities.Columns("Quantity").Text), 2), "0.00")
            ElseIf IsNumeric(grdCommodities.Columns("Customs Val").Text) Then
                grdCommodities.Columns("Unit Value").Text = CDbl(grdCommodities.Columns("Customs Val").Text) / CDbl(grdCommodities.Columns("Quantity").Text)
            End If
        End If
    End If
    If grdCommodities.Columns(ColIndex).Caption = "Unit Value" Then
        If IsNumeric(grdCommodities.Columns("Unit Value").Text) Then
            If IsNumeric(grdCommodities.Columns("Quantity").Text) Then
                grdCommodities.Columns("Customs Val").Text = Format(Round(CDbl(grdCommodities.Columns("Unit Value").Text) * CDbl(grdCommodities.Columns("Quantity").Text), 2))
            End If
        End If
    End If

    If grdCommodities.Columns("f1").Text = "" Then
        With frmShip
            If .f1.Visible Then
                grdCommodities.Columns("f1").Text = .f1
            Else
                grdCommodities.Columns("f1").Text = .cboCustID
            End If
        End With
    End If

    If grdCommodities.Columns("Cntry of Mfg").Text <> UCase(grdCommodities.Columns("Cntry of Mfg").Text) Then
        grdCommodities.Columns("Cntry of Mfg").Text = UCase(grdCommodities.Columns("Cntry of Mfg").Text)
    End If
    
    If grdCommodities.Columns("Workstation").Text = "" Then
        'debugprint "grdCommodities_AfterColUpdate", "WS"
        grdCommodities.Columns("Workstation").Text = g_strComputerName
    End If

    Call AfterLostFocus(grdCommodities)

ErrorExit:
    Exit Sub
EH:
    MsgBox Err.Description, vbCritical, "frmCommodities:grdCommodities_AfterColUpdate"

End Sub

Private Sub grdCommodities_Change()
    On Error GoTo EH
'    DebugPrint "grdCommodities_Change, Value " & grdCommodities.Columns(grdCommodities.col).Text & ", index " & grdCommodities.col

    If grdCommodities.Columns(grdCommodities.col).Caption = "Customs Val" Then
        If IsNumeric(grdCommodities.Columns("Customs Val").Text) Then
            If IsNumeric(grdCommodities.Columns("Quantity").Text) Then
                grdCommodities.Columns("Unit Value").Text = CDbl(grdCommodities.Columns("Customs Val").Text) / CDbl(grdCommodities.Columns("Quantity").Text)
            End If
        End If
    End If
    If grdCommodities.Columns(grdCommodities.col).Caption = "Quantity" Then
        If IsNumeric(grdCommodities.Columns("Quantity").Text) Then
            If IsNumeric(grdCommodities.Columns("Unit Value").Text) Then
                grdCommodities.Columns("Customs Val").Text = CDbl(grdCommodities.Columns("Unit Value").Text) * CDbl(grdCommodities.Columns("Quantity").Text)
            ElseIf IsNumeric(grdCommodities.Columns("Customs Val").Text) Then
                grdCommodities.Columns("Unit Value").Text = CDbl(grdCommodities.Columns("Customs Val").Text) / CDbl(grdCommodities.Columns("Quantity").Text)
            End If
        End If
    End If
    If grdCommodities.Columns(grdCommodities.col).Caption = "Unit Value" Then
        If IsNumeric(grdCommodities.Columns("Unit Value").Text) Then
            If IsNumeric(grdCommodities.Columns("Quantity").Text) Then
                grdCommodities.Columns("Customs Val").Text = CDbl(grdCommodities.Columns("Unit Value").Text) * CDbl(grdCommodities.Columns("Quantity").Text)
            End If
        End If
    End If
ErrorExit:
    Exit Sub
EH:
    MsgBox Err.Description, vbCritical, "frmCommodities:grdCommodities_Change"

End Sub

Private Sub grdCommodities_ColEdit(ByVal ColIndex As Integer)
    On Error Resume Next
'    DebugPrint "grdCommodities_ColEdit, Value " & grdCommodities.Columns(ColIndex).Text & ", index " & ColIndex
End Sub

Private Sub grdCommodities_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
    On Error Resume Next
'    DebugPrint "grdCommodities_RowColChange, Last row col " & LastRow & " " & LastCol
End Sub

